<?php
	/**
	 * This is a MetaControl class, providing a QForm or QPanel access to event handlers
	 * and QControls to perform the Create, Edit, and Delete functionality
	 * of the Borrowings class.  This code-generated class
	 * contains all the basic elements to help a QPanel or QForm display an HTML form that can
	 * manipulate a single Borrowings object.
	 *
	 * To take advantage of some (or all) of these control objects, you
	 * must create a new QForm or QPanel which instantiates a BorrowingsMetaControl
	 * class.
	 *
	 * Any and all changes to this file will be overwritten with any subsequent
	 * code re-generation.
	 * 
	 * @package My Application
	 * @subpackage MetaControls
	 * property-read Borrowings $Borrowings the actual Borrowings data class being edited
	 * property QLabel $IdControl
	 * property-read QLabel $IdLabel
	 * property QIntegerTextBox $AssetControl
	 * property-read QLabel $AssetLabel
	 * property QIntegerTextBox $PersonControl
	 * property-read QLabel $PersonLabel
	 * property QIntegerTextBox $BorrowDirectionControl
	 * property-read QLabel $BorrowDirectionLabel
	 * property QDateTimePicker $BorrowDateControl
	 * property-read QLabel $BorrowDateLabel
	 * property QDateTimePicker $ExpectedReturnDateControl
	 * property-read QLabel $ExpectedReturnDateLabel
	 * property QDateTimePicker $ReturnDateControl
	 * property-read QLabel $ReturnDateLabel
	 * property-read string $TitleVerb a verb indicating whether or not this is being edited or created
	 * property-read boolean $EditMode a boolean indicating whether or not this is being edited or created
	 */

	class BorrowingsMetaControlGen extends QBaseClass {
		// General Variables
		protected $objBorrowings;
		protected $objParentObject;
		protected $strTitleVerb;
		protected $blnEditMode;

		// Controls that allow the editing of Borrowings's individual data fields
		protected $lblId;
		protected $txtAsset;
		protected $txtPerson;
		protected $txtBorrowDirection;
		protected $calBorrowDate;
		protected $calExpectedReturnDate;
		protected $calReturnDate;

		// Controls that allow the viewing of Borrowings's individual data fields
		protected $lblAsset;
		protected $lblPerson;
		protected $lblBorrowDirection;
		protected $lblBorrowDate;
		protected $lblExpectedReturnDate;
		protected $lblReturnDate;

		// QListBox Controls (if applicable) to edit Unique ReverseReferences and ManyToMany References

		// QLabel Controls (if applicable) to view Unique ReverseReferences and ManyToMany References


		/**
		 * Main constructor.  Constructor OR static create methods are designed to be called in either
		 * a parent QPanel or the main QForm when wanting to create a
		 * BorrowingsMetaControl to edit a single Borrowings object within the
		 * QPanel or QForm.
		 *
		 * This constructor takes in a single Borrowings object, while any of the static
		 * create methods below can be used to construct based off of individual PK ID(s).
		 *
		 * @param mixed $objParentObject QForm or QPanel which will be using this BorrowingsMetaControl
		 * @param Borrowings $objBorrowings new or existing Borrowings object
		 */
		 public function __construct($objParentObject, Borrowings $objBorrowings) {
			// Setup Parent Object (e.g. QForm or QPanel which will be using this BorrowingsMetaControl)
			$this->objParentObject = $objParentObject;

			// Setup linked Borrowings object
			$this->objBorrowings = $objBorrowings;

			// Figure out if we're Editing or Creating New
			if ($this->objBorrowings->__Restored) {
				$this->strTitleVerb = QApplication::Translate('Edit');
				$this->blnEditMode = true;
			} else {
				$this->strTitleVerb = QApplication::Translate('Create');
				$this->blnEditMode = false;
			}
		 }

		/**
		 * Static Helper Method to Create using PK arguments
		 * You must pass in the PK arguments on an object to load, or leave it blank to create a new one.
		 * If you want to load via QueryString or PathInfo, use the CreateFromQueryString or CreateFromPathInfo
		 * static helper methods.  Finally, specify a CreateType to define whether or not we are only allowed to 
		 * edit, or if we are also allowed to create a new one, etc.
		 * 
		 * @param mixed $objParentObject QForm or QPanel which will be using this BorrowingsMetaControl
		 * @param integer $intId primary key value
		 * @param QMetaControlCreateType $intCreateType rules governing Borrowings object creation - defaults to CreateOrEdit
 		 * @return BorrowingsMetaControl
		 */
		public static function Create($objParentObject, $intId = null, $intCreateType = QMetaControlCreateType::CreateOrEdit) {
			// Attempt to Load from PK Arguments
			if (strlen($intId)) {
				$objBorrowings = Borrowings::Load($intId);

				// Borrowings was found -- return it!
				if ($objBorrowings)
					return new BorrowingsMetaControl($objParentObject, $objBorrowings);

				// If CreateOnRecordNotFound not specified, throw an exception
				else if ($intCreateType != QMetaControlCreateType::CreateOnRecordNotFound)
					throw new QCallerException('Could not find a Borrowings object with PK arguments: ' . $intId);

			// If EditOnly is specified, throw an exception
			} else if ($intCreateType == QMetaControlCreateType::EditOnly)
				throw new QCallerException('No PK arguments specified');

			// If we are here, then we need to create a new record
			return new BorrowingsMetaControl($objParentObject, new Borrowings());
		}

		/**
		 * Static Helper Method to Create using PathInfo arguments
		 *
		 * @param mixed $objParentObject QForm or QPanel which will be using this BorrowingsMetaControl
		 * @param QMetaControlCreateType $intCreateType rules governing Borrowings object creation - defaults to CreateOrEdit
		 * @return BorrowingsMetaControl
		 */
		public static function CreateFromPathInfo($objParentObject, $intCreateType = QMetaControlCreateType::CreateOrEdit) {
			$intId = QApplication::PathInfo(0);
			return BorrowingsMetaControl::Create($objParentObject, $intId, $intCreateType);
		}

		/**
		 * Static Helper Method to Create using QueryString arguments
		 *
		 * @param mixed $objParentObject QForm or QPanel which will be using this BorrowingsMetaControl
		 * @param QMetaControlCreateType $intCreateType rules governing Borrowings object creation - defaults to CreateOrEdit
		 * @return BorrowingsMetaControl
		 */
		public static function CreateFromQueryString($objParentObject, $intCreateType = QMetaControlCreateType::CreateOrEdit) {
			$intId = QApplication::QueryString('intId');
			return BorrowingsMetaControl::Create($objParentObject, $intId, $intCreateType);
		}



		///////////////////////////////////////////////
		// PUBLIC CREATE and REFRESH METHODS
		///////////////////////////////////////////////

		/**
		 * Create and setup QLabel lblId
		 * @param string $strControlId optional ControlId to use
		 * @return QLabel
		 */
		public function lblId_Create($strControlId = null) {
			$this->lblId = new QLabel($this->objParentObject, $strControlId);
			$this->lblId->Name = QApplication::Translate('Id');
			if ($this->blnEditMode)
				$this->lblId->Text = $this->objBorrowings->Id;
			else
				$this->lblId->Text = 'N/A';
			return $this->lblId;
		}

		/**
		 * Create and setup QIntegerTextBox txtAsset
		 * @param string $strControlId optional ControlId to use
		 * @return QIntegerTextBox
		 */
		public function txtAsset_Create($strControlId = null) {
			$this->txtAsset = new QIntegerTextBox($this->objParentObject, $strControlId);
			$this->txtAsset->Name = QApplication::Translate('Asset');
			$this->txtAsset->Text = $this->objBorrowings->Asset;
			$this->txtAsset->Required = true;
			return $this->txtAsset;
		}

		/**
		 * Create and setup QLabel lblAsset
		 * @param string $strControlId optional ControlId to use
		 * @param string $strFormat optional sprintf format to use
		 * @return QLabel
		 */
		public function lblAsset_Create($strControlId = null, $strFormat = null) {
			$this->lblAsset = new QLabel($this->objParentObject, $strControlId);
			$this->lblAsset->Name = QApplication::Translate('Asset');
			$this->lblAsset->Text = $this->objBorrowings->Asset;
			$this->lblAsset->Required = true;
			$this->lblAsset->Format = $strFormat;
			return $this->lblAsset;
		}

		/**
		 * Create and setup QIntegerTextBox txtPerson
		 * @param string $strControlId optional ControlId to use
		 * @return QIntegerTextBox
		 */
		public function txtPerson_Create($strControlId = null) {
			$this->txtPerson = new QIntegerTextBox($this->objParentObject, $strControlId);
			$this->txtPerson->Name = QApplication::Translate('Person');
			$this->txtPerson->Text = $this->objBorrowings->Person;
			$this->txtPerson->Required = true;
			return $this->txtPerson;
		}

		/**
		 * Create and setup QLabel lblPerson
		 * @param string $strControlId optional ControlId to use
		 * @param string $strFormat optional sprintf format to use
		 * @return QLabel
		 */
		public function lblPerson_Create($strControlId = null, $strFormat = null) {
			$this->lblPerson = new QLabel($this->objParentObject, $strControlId);
			$this->lblPerson->Name = QApplication::Translate('Person');
			$this->lblPerson->Text = $this->objBorrowings->Person;
			$this->lblPerson->Required = true;
			$this->lblPerson->Format = $strFormat;
			return $this->lblPerson;
		}

		/**
		 * Create and setup QIntegerTextBox txtBorrowDirection
		 * @param string $strControlId optional ControlId to use
		 * @return QIntegerTextBox
		 */
		public function txtBorrowDirection_Create($strControlId = null) {
			$this->txtBorrowDirection = new QIntegerTextBox($this->objParentObject, $strControlId);
			$this->txtBorrowDirection->Name = QApplication::Translate('Borrow Direction');
			$this->txtBorrowDirection->Text = $this->objBorrowings->BorrowDirection;
			return $this->txtBorrowDirection;
		}

		/**
		 * Create and setup QLabel lblBorrowDirection
		 * @param string $strControlId optional ControlId to use
		 * @param string $strFormat optional sprintf format to use
		 * @return QLabel
		 */
		public function lblBorrowDirection_Create($strControlId = null, $strFormat = null) {
			$this->lblBorrowDirection = new QLabel($this->objParentObject, $strControlId);
			$this->lblBorrowDirection->Name = QApplication::Translate('Borrow Direction');
			$this->lblBorrowDirection->Text = $this->objBorrowings->BorrowDirection;
			$this->lblBorrowDirection->Format = $strFormat;
			return $this->lblBorrowDirection;
		}

		/**
		 * Create and setup QDateTimePicker calBorrowDate
		 * @param string $strControlId optional ControlId to use
		 * @return QDateTimePicker
		 */
		public function calBorrowDate_Create($strControlId = null) {
			$this->calBorrowDate = new QDateTimePicker($this->objParentObject, $strControlId);
			$this->calBorrowDate->Name = QApplication::Translate('Borrow Date');
			$this->calBorrowDate->DateTime = $this->objBorrowings->BorrowDate;
			$this->calBorrowDate->DateTimePickerType = QDateTimePickerType::Date;
			$this->calBorrowDate->Required = true;
			return $this->calBorrowDate;
		}

		/**
		 * Create and setup QLabel lblBorrowDate
		 * @param string $strControlId optional ControlId to use
		 * @param string $strDateTimeFormat optional DateTimeFormat to use
		 * @return QLabel
		 */
		public function lblBorrowDate_Create($strControlId = null, $strDateTimeFormat = null) {
			$this->lblBorrowDate = new QLabel($this->objParentObject, $strControlId);
			$this->lblBorrowDate->Name = QApplication::Translate('Borrow Date');
			$this->strBorrowDateDateTimeFormat = $strDateTimeFormat;
			$this->lblBorrowDate->Text = sprintf($this->objBorrowings->BorrowDate) ? $this->objBorrowings->BorrowDate->__toString($this->strBorrowDateDateTimeFormat) : null;
			$this->lblBorrowDate->Required = true;
			return $this->lblBorrowDate;
		}

		protected $strBorrowDateDateTimeFormat;


		/**
		 * Create and setup QDateTimePicker calExpectedReturnDate
		 * @param string $strControlId optional ControlId to use
		 * @return QDateTimePicker
		 */
		public function calExpectedReturnDate_Create($strControlId = null) {
			$this->calExpectedReturnDate = new QDateTimePicker($this->objParentObject, $strControlId);
			$this->calExpectedReturnDate->Name = QApplication::Translate('Expected Return Date');
			$this->calExpectedReturnDate->DateTime = $this->objBorrowings->ExpectedReturnDate;
			$this->calExpectedReturnDate->DateTimePickerType = QDateTimePickerType::Date;
			$this->calExpectedReturnDate->Required = true;
			return $this->calExpectedReturnDate;
		}

		/**
		 * Create and setup QLabel lblExpectedReturnDate
		 * @param string $strControlId optional ControlId to use
		 * @param string $strDateTimeFormat optional DateTimeFormat to use
		 * @return QLabel
		 */
		public function lblExpectedReturnDate_Create($strControlId = null, $strDateTimeFormat = null) {
			$this->lblExpectedReturnDate = new QLabel($this->objParentObject, $strControlId);
			$this->lblExpectedReturnDate->Name = QApplication::Translate('Expected Return Date');
			$this->strExpectedReturnDateDateTimeFormat = $strDateTimeFormat;
			$this->lblExpectedReturnDate->Text = sprintf($this->objBorrowings->ExpectedReturnDate) ? $this->objBorrowings->ExpectedReturnDate->__toString($this->strExpectedReturnDateDateTimeFormat) : null;
			$this->lblExpectedReturnDate->Required = true;
			return $this->lblExpectedReturnDate;
		}

		protected $strExpectedReturnDateDateTimeFormat;


		/**
		 * Create and setup QDateTimePicker calReturnDate
		 * @param string $strControlId optional ControlId to use
		 * @return QDateTimePicker
		 */
		public function calReturnDate_Create($strControlId = null) {
			$this->calReturnDate = new QDateTimePicker($this->objParentObject, $strControlId);
			$this->calReturnDate->Name = QApplication::Translate('Return Date');
			$this->calReturnDate->DateTime = $this->objBorrowings->ReturnDate;
			$this->calReturnDate->DateTimePickerType = QDateTimePickerType::Date;
			return $this->calReturnDate;
		}

		/**
		 * Create and setup QLabel lblReturnDate
		 * @param string $strControlId optional ControlId to use
		 * @param string $strDateTimeFormat optional DateTimeFormat to use
		 * @return QLabel
		 */
		public function lblReturnDate_Create($strControlId = null, $strDateTimeFormat = null) {
			$this->lblReturnDate = new QLabel($this->objParentObject, $strControlId);
			$this->lblReturnDate->Name = QApplication::Translate('Return Date');
			$this->strReturnDateDateTimeFormat = $strDateTimeFormat;
			$this->lblReturnDate->Text = sprintf($this->objBorrowings->ReturnDate) ? $this->objBorrowings->ReturnDate->__toString($this->strReturnDateDateTimeFormat) : null;
			return $this->lblReturnDate;
		}

		protected $strReturnDateDateTimeFormat;




		/**
		 * Refresh this MetaControl with Data from the local Borrowings object.
		 * @param boolean $blnReload reload Borrowings from the database
		 * @return void
		 */
		public function Refresh($blnReload = false) {
			if ($blnReload)
				$this->objBorrowings->Reload();

			if ($this->lblId) if ($this->blnEditMode) $this->lblId->Text = $this->objBorrowings->Id;

			if ($this->txtAsset) $this->txtAsset->Text = $this->objBorrowings->Asset;
			if ($this->lblAsset) $this->lblAsset->Text = $this->objBorrowings->Asset;

			if ($this->txtPerson) $this->txtPerson->Text = $this->objBorrowings->Person;
			if ($this->lblPerson) $this->lblPerson->Text = $this->objBorrowings->Person;

			if ($this->txtBorrowDirection) $this->txtBorrowDirection->Text = $this->objBorrowings->BorrowDirection;
			if ($this->lblBorrowDirection) $this->lblBorrowDirection->Text = $this->objBorrowings->BorrowDirection;

			if ($this->calBorrowDate) $this->calBorrowDate->DateTime = $this->objBorrowings->BorrowDate;
			if ($this->lblBorrowDate) $this->lblBorrowDate->Text = sprintf($this->objBorrowings->BorrowDate) ? $this->objBorrowings->__toString($this->strBorrowDateDateTimeFormat) : null;

			if ($this->calExpectedReturnDate) $this->calExpectedReturnDate->DateTime = $this->objBorrowings->ExpectedReturnDate;
			if ($this->lblExpectedReturnDate) $this->lblExpectedReturnDate->Text = sprintf($this->objBorrowings->ExpectedReturnDate) ? $this->objBorrowings->__toString($this->strExpectedReturnDateDateTimeFormat) : null;

			if ($this->calReturnDate) $this->calReturnDate->DateTime = $this->objBorrowings->ReturnDate;
			if ($this->lblReturnDate) $this->lblReturnDate->Text = sprintf($this->objBorrowings->ReturnDate) ? $this->objBorrowings->__toString($this->strReturnDateDateTimeFormat) : null;

		}



		///////////////////////////////////////////////
		// PROTECTED UPDATE METHODS for ManyToManyReferences (if any)
		///////////////////////////////////////////////





		///////////////////////////////////////////////
		// PUBLIC BORROWINGS OBJECT MANIPULATORS
		///////////////////////////////////////////////

		/**
		 * This will save this object's Borrowings instance,
		 * updating only the fields which have had a control created for it.
		 */
		public function SaveBorrowings() {
			try {
				// Update any fields for controls that have been created
				if ($this->txtAsset) $this->objBorrowings->Asset = $this->txtAsset->Text;
				if ($this->txtPerson) $this->objBorrowings->Person = $this->txtPerson->Text;
				if ($this->txtBorrowDirection) $this->objBorrowings->BorrowDirection = $this->txtBorrowDirection->Text;
				if ($this->calBorrowDate) $this->objBorrowings->BorrowDate = $this->calBorrowDate->DateTime;
				if ($this->calExpectedReturnDate) $this->objBorrowings->ExpectedReturnDate = $this->calExpectedReturnDate->DateTime;
				if ($this->calReturnDate) $this->objBorrowings->ReturnDate = $this->calReturnDate->DateTime;

				// Update any UniqueReverseReferences (if any) for controls that have been created for it

				// Save the Borrowings object
				$this->objBorrowings->Save();

				// Finally, update any ManyToManyReferences (if any)
			} catch (QCallerException $objExc) {
				$objExc->IncrementOffset();
				throw $objExc;
			}
		}

		/**
		 * This will DELETE this object's Borrowings instance from the database.
		 * It will also unassociate itself from any ManyToManyReferences.
		 */
		public function DeleteBorrowings() {
			$this->objBorrowings->Delete();
		}		



		///////////////////////////////////////////////
		// PUBLIC GETTERS and SETTERS
		///////////////////////////////////////////////

		/**
		 * Override method to perform a property "Get"
		 * This will get the value of $strName
		 *
		 * @param string $strName Name of the property to get
		 * @return mixed
		 */
		public function __get($strName) {
			switch ($strName) {
				// General MetaControlVariables
				case 'Borrowings': return $this->objBorrowings;
				case 'TitleVerb': return $this->strTitleVerb;
				case 'EditMode': return $this->blnEditMode;

				// Controls that point to Borrowings fields -- will be created dynamically if not yet created
				case 'IdControl':
					if (!$this->lblId) return $this->lblId_Create();
					return $this->lblId;
				case 'IdLabel':
					if (!$this->lblId) return $this->lblId_Create();
					return $this->lblId;
				case 'AssetControl':
					if (!$this->txtAsset) return $this->txtAsset_Create();
					return $this->txtAsset;
				case 'AssetLabel':
					if (!$this->lblAsset) return $this->lblAsset_Create();
					return $this->lblAsset;
				case 'PersonControl':
					if (!$this->txtPerson) return $this->txtPerson_Create();
					return $this->txtPerson;
				case 'PersonLabel':
					if (!$this->lblPerson) return $this->lblPerson_Create();
					return $this->lblPerson;
				case 'BorrowDirectionControl':
					if (!$this->txtBorrowDirection) return $this->txtBorrowDirection_Create();
					return $this->txtBorrowDirection;
				case 'BorrowDirectionLabel':
					if (!$this->lblBorrowDirection) return $this->lblBorrowDirection_Create();
					return $this->lblBorrowDirection;
				case 'BorrowDateControl':
					if (!$this->calBorrowDate) return $this->calBorrowDate_Create();
					return $this->calBorrowDate;
				case 'BorrowDateLabel':
					if (!$this->lblBorrowDate) return $this->lblBorrowDate_Create();
					return $this->lblBorrowDate;
				case 'ExpectedReturnDateControl':
					if (!$this->calExpectedReturnDate) return $this->calExpectedReturnDate_Create();
					return $this->calExpectedReturnDate;
				case 'ExpectedReturnDateLabel':
					if (!$this->lblExpectedReturnDate) return $this->lblExpectedReturnDate_Create();
					return $this->lblExpectedReturnDate;
				case 'ReturnDateControl':
					if (!$this->calReturnDate) return $this->calReturnDate_Create();
					return $this->calReturnDate;
				case 'ReturnDateLabel':
					if (!$this->lblReturnDate) return $this->lblReturnDate_Create();
					return $this->lblReturnDate;
				default:
					try {
						return parent::__get($strName);
					} catch (QCallerException $objExc) {
						$objExc->IncrementOffset();
						throw $objExc;
					}
			}
		}

		/**
		 * Override method to perform a property "Set"
		 * This will set the property $strName to be $mixValue
		 *
		 * @param string $strName Name of the property to set
		 * @param string $mixValue New value of the property
		 * @return mixed
		 */
		public function __set($strName, $mixValue) {
			try {
				switch ($strName) {
					// Controls that point to Borrowings fields
					case 'IdControl':
						return ($this->lblId = QType::Cast($mixValue, 'QControl'));
					case 'AssetControl':
						return ($this->txtAsset = QType::Cast($mixValue, 'QControl'));
					case 'PersonControl':
						return ($this->txtPerson = QType::Cast($mixValue, 'QControl'));
					case 'BorrowDirectionControl':
						return ($this->txtBorrowDirection = QType::Cast($mixValue, 'QControl'));
					case 'BorrowDateControl':
						return ($this->calBorrowDate = QType::Cast($mixValue, 'QControl'));
					case 'ExpectedReturnDateControl':
						return ($this->calExpectedReturnDate = QType::Cast($mixValue, 'QControl'));
					case 'ReturnDateControl':
						return ($this->calReturnDate = QType::Cast($mixValue, 'QControl'));
					default:
						return parent::__set($strName, $mixValue);
				}
			} catch (QCallerException $objExc) {
				$objExc->IncrementOffset();
				throw $objExc;
			}
		}
	}
?>